package br.ufpe.cin.plebeia.report;

import java.awt.Image;
import java.util.Set;
import java.util.Map.Entry;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;

import br.ufpe.cin.plebeia.persistence.hibernateDao.HibernateAbelhaDao;

public class ReportBuilder {

	public Image gerarRelatorioAbelhasPorSexo(int i, int j) {
		DefaultPieDataset data = new DefaultPieDataset();
		Set<Entry<Comparable, Number>> dados = new HibernateAbelhaDao()
				.retrieveAbelhasPorSexo().entrySet();

		for (Entry<Comparable, Number> entry : dados) {
			data.setValue(entry.getKey(), entry.getValue());
		}
		JFreeChart chart = ChartFactory.createPieChart3D("Abelhas Por Sexo",
				data, true, true, true);
		chart.getPlot().setBackgroundAlpha(0.8f);

		return chart.createBufferedImage(i, j);

	}

	public static void main(String[] args) {
		JFrame frame = new JFrame();

		Image image = new ReportBuilder()
				.gerarRelatorioAbelhasPorSexo(600, 340);
		frame.setSize(800, 600);
		ImageIcon icon = new ImageIcon(image);
		JLabel label = new JLabel(icon);
		frame.add(label);
		frame.setVisible(true);
	}

}
